%% -*- coding: utf-8 -*-

%% @doc templel_scan のテスト
%%
-module(t_templel_scan).
-import(templel_scan, [string/1]).

-include_lib("eunit/include/eunit.hrl").


string_test_() ->
	[?_assertMatch([],
				   string("")),
	 ?_assertMatch([], 
				   string("\n\n\b\t\s\n")),
	 ?_assertMatch([{'.',[1]},{'[',[1]},{']',[1]},
						{'(',[2]},{',',[2]},{')',[2]},
						{'|',[3]},{'$',[3]},{'@',[3]},{'<',[3]},{'>',[3]},{'!',[3]}],
				   string(".[ ]\n  (, )\n|$@<>!")),

	 % 論理演算子
	 ?_assertMatch([{'==',[1]},{'==',[1]},{'==',[1]},
						{'!=',[1]},{'<=',[1]},{'<',[1]},{'>=',[1]},{'>',[1]},
						{'&&',[2]},{'||',[2]},{'!',[2]}],
				   string("======!=<=<>=> \n &&||!")),
	 ?_assertMatch([{'==',[1]},{'==',[1]},{'==',[1]},
						{'!=',[1]},{'<=',[1]},{'<',[1]},{'>=',[1]},{'>',[1]},
						{'&&',[2]},{'||',[2]},{'!',[2]}],
				   string("======!=<=<>=> \n &&||!")),

	 % 真偽値
	 ?_assertMatch([{boolean,[1],true},{',',[1]},{boolean,[1],false}],
				   string("true,false")),
	 ?_assertMatch([{name,[1],"truefalse"}],
				   string("truefalse")),

	 % 数字
	 ?_assertMatch([{'-',[1]},{integer,[1],0},{integer,[1],0},{integer,[1],1203}],
				   string("-001203")),
	 ?_assertMatch([{integer,[1],2222222222222222}],
				   string("2222222222222222")),

	 % 文字列
	 ?_assertMatch([{string,[1],[]}],
				   string("\"\"")),
	 ?_assertMatch([{string,[1],"hoge"}],
				   string("\"hoge\"")),
	 ?_assertThrow({{templel_scan,einval},{[1],templel_scan,{string,34,"hog"}}},
				   string("\"hog")),
	 ?_assertMatch([{string,[1],"\"\b\n\t"}],
				   string("\"\\\"\b\n\t\"")),
	 ?_assertMatch([{string,[1],"\n\\\t"}],
				   string("\"\\n\\\\\\t\"")),

	 ?_assertThrow({{templel_scan,einval}, _}, 
				   string("\"\\a\"")),
	 ?_assertThrow({{templel_scan,einval}, _}, 
				   string("\"\\a")),
	 ?_assertMatch([{string,[1],"AȦ㊙"}], 
				   string("\"\\u0041\\u0226\\u3299\"")),
	 ?_assertThrow({{templel_scan,einval},{[1],templel_scan,{string,34,[]}}},
				   string("\"\\")),
	 ?_assertThrow({{templel_scan,einval}, _}, 
				   string("\"\\u3B\"")),
	 ?_assertThrow({{templel_scan,einval}, _}, 
				   string("\"\\u3B")),

	 ?_assertMatch([{string,[1],"hoge"},{'-',[1]},{integer,[1],10},{integer,[2],0},
				   {'[',[2]},{integer,[2],0},{']',[2]},{'.',[2]}],
				   string(" \ \"hoge\"-10\n0[0].")),
	 ?_assertMatch([{name,[1],"hoge"}],
				   string("hoge")),
	 ?_assertMatch([{name,[1],"h0g30_0"},{'-',[1]},{integer,[1],0}],
				   string("h0g30_0-0")),

	 ?_assertThrow({{templel_scan,einval}, _}, 
				   string("ほげ")),
	 ?_assertThrow({{templel_scan,einval}, _}, 
				   string("&"))
	].
